package com.leetcode.algorithm.y22.m09.w1;

/**
 * 134. 加油站
 * 
 * https://leetcode.cn/problems/gas-station/
 * 
 * @author jie.deng
 *
 */
class Question0134Solution01 {

	// 暴力方法
	public int canCompleteCircuit(int[] gas, int[] cost) {
		int len = gas.length;
		for (int startIdx = 0; startIdx < len; startIdx++) {
			int remain = 0;
			int i = startIdx;
			while (i < len + startIdx && remain >= 0) {
				int idx = i % len;
				remain += (gas[idx] - cost[idx]);
				i++;
			}
			if (remain >= 0) {
				return startIdx;
			}
		}
		return -1;
	}

}